$(function () {
    var task = function () {
        //数据
        var data = [4, 8, 6, 4, 6, 11];
        var option = {
            backgroundColor: '#151A33',
            title: {
                text: "各督查组负责任务",
                textStyle: {
                    fontSize: 24,
                    color: '#F1E8E8'
                },
                top: 10,
                left: 10
            },
            xAxis: {
                show: true,
                data: ['县委督查室', '县政府督查室', '县作风办', '县效能办', '县纪委驻县政府办纪检组', '县纪委驻县委办纪检组'],
                axisTick: {
                    show: false
                },
                axisLabel: {
                    interval: 0,
                    fontSize: 16,
                    color: '#fff',
                    formatter: function (params) {
                        var newParamsName = "";
                        var paramsNameNumber = params.length;
                        var provideNumber;
                        if (paramsNameNumber <= 6) {
                            provideNumber = 4
                        } else {
                            provideNumber = 6
                        }
                        var rowNumber = Math.ceil(paramsNameNumber / provideNumber);
                        if (paramsNameNumber > provideNumber) {
                            /** 循环每一行,p表示行 */
                            for (var p = 0; p < rowNumber; p++) {
                                var tempStr = "";
                                var start = p * provideNumber;
                                var end = start + provideNumber;
                                if (p == rowNumber - 1) {
                                    // 最后一次不换行
                                    tempStr = params.substring(start, paramsNameNumber);
                                } else {
                                    tempStr = params.substring(start, end) + "\n";
                                }
                                newParamsName += tempStr;
                            }
                        } else {
                            newParamsName = params;
                        }
                        return newParamsName
                    },
                },
            },
            yAxis: {
                show: false,
                interval: 10,
                axisTick: {
                    length: 5,
                },
                splitLine: {
                    show: false
                }
            },
            animationEasing: 'elasticOut',
            series: [{
                animationDuration: 5000,
                type: 'pictorialBar',
                symbol: 'rect',
                symbolRepeat: true,
                symbolSize: [80, 45],
                symbolMargin: 3,
                itemStyle: {
                    normal: {
                        color: {
                            colorStops: [{
                                offset: 0,
                                color: '#3BAEE4' // 0% 处的颜色
                            }, {
                                offset: 1,
                                color: '#3BAEE4' // 100% 处的颜色
                            }],
                        }
                    }

                },
                label: {
                    show: true,
                    position: 'top',
                    fontSize:18,
                    color: '#fff',
                    formatter: '{c}项',
                },
                data: data
            }]
        };
        echarts.init(document.getElementById('task')).setOption(option);
        window.addEventListener("resize", function () {
            echarts.init(document.getElementById('task')).resize();
        });
    }
    // task()
})